package com.software.seakdream.controller;

import com.software.seakdream.domain.Result;
import com.software.seakdream.entity.ClockInfo;
import com.software.seakdream.entity.History;

import com.software.seakdream.entity.HistoryRecord;
import com.software.seakdream.service.HistoryService;

import com.software.seakdream.utils.ResultUtils;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/History")
public class HistoryController {
    @Autowired
    private HistoryService historyService;

    @PostMapping("/createHistory")
    public Result createHistory(History history) {
        History create = historyService.createHistory(history);
        return ResultUtils.success(create);
    }

    @GetMapping("/findHistory")
    public Result findHistory(String userId) {
        List<History> historyList = historyService.findHistory(userId);
        return ResultUtils.success(historyList);
    }

    @GetMapping("/deleteHistory")
    public Result deleteHistory(String userId, String audioId) {
        Boolean delete = historyService.deleteHistory(userId, audioId);
        if (delete) {
            return ResultUtils.success("成功删除");
        } else {
            return ResultUtils.error("404", "无法删除", "删除失败");
        }
    }


    @GetMapping("/getHistoryRecordUsePage")
    public Result getHistoryRecordUsePage(String userId, int page) {
        int pageSize = 20;
        List<HistoryRecord> records = historyService.getHistoryRecordUsePage(userId, page, pageSize);
        return ResultUtils.success(records);
    }

    @GetMapping("/deleteAllHistory")
    public void deleteAllHistory(String userId){
        historyService.deleteAllHistory(userId);
    }
}
